package com.ruoyi.web.controller.his;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.his.domain.HisDept;
import com.ruoyi.his.service.IHisDeptService;
import com.ruoyi.system.domain.SysPost;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author shebin
 * @site www.694840063@qq.com
 * @company 扬州绘鑫勤商贸有限公司
 * @create 2021-08-21 13:07
 */
@RestController
@RequestMapping("/his/dept")
public class hisDeptController extends BaseController {

    @Autowired
    private IHisDeptService HisDeptService;

    /**
     * 获取科室列表
     * @param dept
     * @return
     */
    @PreAuthorize("@ss.hasPermi('his:dept:list')")
    @GetMapping("/list")
    public TableDataInfo list(HisDept dept){
        startPage();
        List<HisDept> list = HisDeptService.selectDeptList(dept);
        return getDataTable(list);
    }

    /**
     * 根据编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('his:dept:query')")
    @GetMapping(value = "/{deptId}")
    public AjaxResult getInfo(@PathVariable Long deptId)
    {
        return AjaxResult.success(HisDeptService.selectDeptById(deptId));
    }

    /**
     * 新增科室
     */
    @PreAuthorize("@ss.hasPermi('his:dept:add')")
    @Log(title = "科室管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody HisDept dept)
    {
        dept.setCreateBy(getUsername());
        return toAjax(HisDeptService.insertDept(dept));
    }

    /**
     * 修改科室
     */
    @PreAuthorize("@ss.hasPermi('his:dept:edit')")
    @Log(title = "科室管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody HisDept dept)
    {
        dept.setUpdateBy(getUsername());
        return toAjax(HisDeptService.updateDept(dept));
    }

    /**
     * 删除科室
     */
    @PreAuthorize("@ss.hasPermi('his:dept:remove')")
    @Log(title = "科室管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{deptIds}")
    public AjaxResult remove(@PathVariable Long[] deptIds){
        return toAjax(HisDeptService.deleteDeptByIds(deptIds));
    }

    @Log(title = "科室管理", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('his:dept:export')")
    @GetMapping("/export")
    public AjaxResult export(HisDept dept)
    {
        List<HisDept> list = HisDeptService.selectDeptList(dept);
        ExcelUtil<HisDept> util = new ExcelUtil(HisDept.class);
        return util.exportExcel(list, "科室数据");
    }
}
